var selectUlHide;
/**
 * 加载下拉框
 * @param id
 * @param data
 * @param valueId
 * @returns
 */
function inputSelect(id, data, valueId) {
	var input = document.getElementById(id);
	var inputDiv = document.createElement("div");
	inputDiv.id = id + "Div";
	inputDiv.style.display = "inline-block";
	//inputDiv.innerHTML = input.innerHTML;
	//inputDiv.appendChild(input);
	//input.parentNode.appendChild(inputDiv);
	input.parentNode.insertBefore(inputDiv, input);
	inputDiv.appendChild(input);
	var listUl = document.createElement("ul");
	listUl.style.display = "none";
	listUl.id = id + "Ul";
	listUl.className = "selectUl";
	listUl.style.position = "absolute";
	listUl.style.width = (inputDiv.offsetWidth - 2) + "px";
	var dataId = data.id;
	var dataValue = data.value;
	var dataList = data.data;
	var liHtml = "";
	for (var i = 0; i < dataList.length; i++) {
		liHtml += "<li class='selectLi' submitValue='"+dataList[i][dataId]+"' onclick='selectLi(this, \"" + id + "\", \"" + valueId + "\");'>"+dataList[i][dataValue]+"</li>";
	}
	listUl.innerHTML = liHtml;
	inputDiv.appendChild(listUl);
	// 设置点击事件
	input.onclick = function() {
		/*
		if (input.value != null && input.value != "") {
			var showData = [];
			for (var i = 0; i < dataList.length; i++) {
				if (dataList[i][dataValue].indexOf(input.value) > -1) {
					showData.push(dataList[i]);
				}
			}
			var liSearchHtml = "";
			for (var i = 0; i < showData.length; i++) {
				liSearchHtml += "<li class='selectLi' submitValue='"+showData[i][dataId]+"' onclick='selectLi(this, \"" + id + "\", \"" + valueId + "\");'>"+showData[i][dataValue]+"</li>";
			}
			listUl.innerHTML = liSearchHtml;
		}
		*/
		var list = document.getElementsByClassName('selectUl');
		for (var i = 0; i < list.length; ++i) {
			list[i].style.display = "none";
	    }
		listUl.style.display = "block";
		selectUlHide = false;
	};
	window.onclick = selectWindowClick;
	input.oninput = function() {
		var showData = [];
		for (var i = 0; i < dataList.length; i++) {
			if (dataList[i][dataValue].indexOf(input.value) > -1) {
				showData.push(dataList[i]);
			}
		}
		var liSearchHtml = "";
		for (var i = 0; i < showData.length; i++) {
			liSearchHtml += "<li class='selectLi' submitValue='"+showData[i][dataId]+"' onclick='selectLi(this, \"" + id + "\", \"" + valueId + "\");'>"+showData[i][dataValue]+"</li>";
		}
		listUl.innerHTML = liSearchHtml;
	};
}
function selectWindowClick() {
	if (selectUlHide) {
		var list = document.getElementsByClassName('selectUl');
		for (var i = 0; i < list.length; ++i) {
			list[i].style.display = "none";
	    }
	}
	selectUlHide = true;
}
/**
 * 选中事件
 * @param li
 * @param id
 * @param valueId
 * @returns
 */
function selectLi(li, id, valueId) {
	document.getElementById(id).value = li.innerHTML;
	if (valueId != "undefined" && valueId != "") {
		document.getElementById(valueId).value = li.getAttribute("submitValue");
	}
}
